package org.nativejpa.samples.firstapp;

import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.Column;
import java.io.Serializable;

/**
 * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
 * @create 2009-8-19 14:36:51
 */
@Entity
@Table(name = "ADDRESS")
@NamedNativeQueries(
        {
                @NamedNativeQuery(name = AddressEntity.NAMED_QUERY_CREATE_TABLE,
                        query = "CREATE TABLE ADDRESS(ID BIGINT NOT NULL, PERSON_ID BIGINT NOT NULL, COUNTRY VARCHAR(50), NAME VARCHAR(100), POSTCODE VARCHAR(20)) "),
                @NamedNativeQuery(name = AddressEntity.NAMED_QUERY_INSERT_ONE,
                        query = "INSERT INTO ADDRESS (ID, PERSON_ID, NAME, COUNTRY, POSTCODE) VALUES ($ADDRESS.getId(), $ADDRESS.getPersonId(), $ADDRESS.getName(), $ADDRESS.getCountry(), $ADDRESS.gePostCode())")
        }
)
public class AddressEntity implements Serializable{

    public static final String NAMED_QUERY_CREATE_TABLE = "ADDRESS.create_table";
    public static final String NAMED_QUERY_INSERT_ONE = "ADDRESS.insert_one";
    public static final String NAMED_QUERY_DELETE_ONE = "ADDRESS.delete_one";
    public static final String NAMED_QUERY_UPDATE_ONE = "ADDRESS.update_one";
    public static final String NAMED_QUERY_SELECT_ONE = "ADDRESS.select_one";
    public static final String NAMED_QUERY_SELECT_ALL = "ADDRESS.select_all";
    public static final String NAMED_QUERY_SELECT_BY_CONDITION = "ADDRESS.select_by_condition";

    @Id
    @Column(name = "ID")
    private long Id;

    @Column(name = "PERSON_ID")
    private long personId;

    @Column(name = "COUNTRY")
    private String country;

    @Column(name = "NAME")
    private String name;

    @Column(name = "POSTCODE")
    private String postCode;

    public long getId() {
        return Id;
    }

    public void setId(long id) {
        Id = id;
    }

    public long getPersonId() {
        return personId;
    }

    public void setPersonId(long personId) {
        this.personId = personId;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPostCode() {
        return postCode;
    }

    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }

    @Override
    public String toString() {
        return this.getClass().getSimpleName() + "{" + "id=" + this.getId() + ", name=" +this.getName()+"}";
    }
}